﻿using System;

namespace HslCommunication.Core
{
	/// <summary>
	/// 字节倒序的转换类<br />
	/// Byte reverse order conversion class
	/// </summary>
	// Token: 0x02000127 RID: 295
	public class ReverseBytesTransform : ByteTransformBase
	{
		/// <inheritdoc cref="M:HslCommunication.Core.ByteTransformBase.#ctor" />
		// Token: 0x06001936 RID: 6454 RVA: 0x0007F216 File Offset: 0x0007D416
		public ReverseBytesTransform()
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Core.ByteTransformBase.#ctor(HslCommunication.Core.DataFormat)" />
		// Token: 0x06001937 RID: 6455 RVA: 0x0007F220 File Offset: 0x0007D420
		public ReverseBytesTransform(DataFormat dataFormat) : base(dataFormat)
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransInt16(System.Byte[],System.Int32)" />
		// Token: 0x06001938 RID: 6456 RVA: 0x0007F258 File Offset: 0x0007D458
		public override short TransInt16(byte[] buffer, int index)
		{
			return BitConverter.ToInt16(new byte[]
			{
				buffer[1 + index],
				buffer[index]
			}, 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransUInt16(System.Byte[],System.Int32)" />
		// Token: 0x06001939 RID: 6457 RVA: 0x0007F288 File Offset: 0x0007D488
		public override ushort TransUInt16(byte[] buffer, int index)
		{
			return BitConverter.ToUInt16(new byte[]
			{
				buffer[1 + index],
				buffer[index]
			}, 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransInt32(System.Byte[],System.Int32)" />
		// Token: 0x0600193A RID: 6458 RVA: 0x0007F2B8 File Offset: 0x0007D4B8
		public override int TransInt32(byte[] buffer, int index)
		{
			return BitConverter.ToInt32(base.ByteTransDataFormat4(new byte[]
			{
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransUInt32(System.Byte[],System.Int32)" />
		// Token: 0x0600193B RID: 6459 RVA: 0x0007F300 File Offset: 0x0007D500
		public override uint TransUInt32(byte[] buffer, int index)
		{
			return BitConverter.ToUInt32(base.ByteTransDataFormat4(new byte[]
			{
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransInt64(System.Byte[],System.Int32)" />
		// Token: 0x0600193C RID: 6460 RVA: 0x0007F348 File Offset: 0x0007D548
		public override long TransInt64(byte[] buffer, int index)
		{
			return BitConverter.ToInt64(base.ByteTransDataFormat8(new byte[]
			{
				buffer[7 + index],
				buffer[6 + index],
				buffer[5 + index],
				buffer[4 + index],
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransUInt64(System.Byte[],System.Int32)" />
		// Token: 0x0600193D RID: 6461 RVA: 0x0007F3B0 File Offset: 0x0007D5B0
		public override ulong TransUInt64(byte[] buffer, int index)
		{
			return BitConverter.ToUInt64(base.ByteTransDataFormat8(new byte[]
			{
				buffer[7 + index],
				buffer[6 + index],
				buffer[5 + index],
				buffer[4 + index],
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransSingle(System.Byte[],System.Int32)" />
		// Token: 0x0600193E RID: 6462 RVA: 0x0007F418 File Offset: 0x0007D618
		public override float TransSingle(byte[] buffer, int index)
		{
			return BitConverter.ToSingle(base.ByteTransDataFormat4(new byte[]
			{
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransDouble(System.Byte[],System.Int32)" />
		// Token: 0x0600193F RID: 6463 RVA: 0x0007F460 File Offset: 0x0007D660
		public override double TransDouble(byte[] buffer, int index)
		{
			return BitConverter.ToDouble(base.ByteTransDataFormat8(new byte[]
			{
				buffer[7 + index],
				buffer[6 + index],
				buffer[5 + index],
				buffer[4 + index],
				buffer[3 + index],
				buffer[2 + index],
				buffer[1 + index],
				buffer[index]
			}, 0), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Int16[])" />
		// Token: 0x06001940 RID: 6464 RVA: 0x0007F4C8 File Offset: 0x0007D6C8
		public override byte[] TransByte(short[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 2];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					bytes.CopyTo(array, 2 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.UInt16[])" />
		// Token: 0x06001941 RID: 6465 RVA: 0x0007F528 File Offset: 0x0007D728
		public override byte[] TransByte(ushort[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 2];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					bytes.CopyTo(array, 2 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Int32[])" />
		// Token: 0x06001942 RID: 6466 RVA: 0x0007F588 File Offset: 0x0007D788
		public override byte[] TransByte(int[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 4];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat4(bytes, 0).CopyTo(array, 4 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.UInt32[])" />
		// Token: 0x06001943 RID: 6467 RVA: 0x0007F5F0 File Offset: 0x0007D7F0
		public override byte[] TransByte(uint[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 4];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat4(bytes, 0).CopyTo(array, 4 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Int64[])" />
		// Token: 0x06001944 RID: 6468 RVA: 0x0007F658 File Offset: 0x0007D858
		public override byte[] TransByte(long[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 8];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat8(bytes, 0).CopyTo(array, 8 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.UInt64[])" />
		// Token: 0x06001945 RID: 6469 RVA: 0x0007F6C0 File Offset: 0x0007D8C0
		public override byte[] TransByte(ulong[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 8];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat8(bytes, 0).CopyTo(array, 8 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Single[])" />
		// Token: 0x06001946 RID: 6470 RVA: 0x0007F728 File Offset: 0x0007D928
		public override byte[] TransByte(float[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 4];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat4(bytes, 0).CopyTo(array, 4 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Double[])" />
		/// <returns>buffer数据</returns>
		// Token: 0x06001947 RID: 6471 RVA: 0x0007F790 File Offset: 0x0007D990
		public override byte[] TransByte(double[] values)
		{
			bool flag = values == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				byte[] array = new byte[values.Length * 8];
				for (int i = 0; i < values.Length; i++)
				{
					byte[] bytes = BitConverter.GetBytes(values[i]);
					Array.Reverse(bytes);
					base.ByteTransDataFormat8(bytes, 0).CopyTo(array, 8 * i);
				}
				result = array;
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.CreateByDateFormat(HslCommunication.Core.DataFormat)" />
		// Token: 0x06001948 RID: 6472 RVA: 0x0007F7F5 File Offset: 0x0007D9F5
		public override IByteTransform CreateByDateFormat(DataFormat dataFormat)
		{
			return new ReverseBytesTransform(dataFormat)
			{
				IsStringReverseByteWord = base.IsStringReverseByteWord
			};
		}

		/// <inheritdoc />
		// Token: 0x06001949 RID: 6473 RVA: 0x0007F80A File Offset: 0x0007DA0A
		public override string ToString()
		{
			return string.Format("ReverseBytesTransform[{0}]", base.DataFormat);
		}
	}
}
